﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System.Windows;
using System.Windows.Controls;
using Majesty_of_Omega.Config;

#endregion

namespace Majesty_of_Omega.GUI.Pages.Game.Research.Parts
{
    /// <summary>
    /// Interaktionslogik für TechnicalInformation.xaml
    /// </summary>
    public partial class TechnicalInformationPart
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TechnicalInformationPart"/> class.
        /// </summary>
        public TechnicalInformationPart()
        {
            InitializeComponent();
            SetFundingVisibleChange(false);
        }

        #region Dependency Property  FundingVisible 

        /// <summary>
        /// Dependency property FundingVisible
        /// </summary>
        public static readonly DependencyProperty FundingVisibleProperty =
            DependencyProperty.Register("FundingVisible", typeof (bool), typeof (TechnicalInformationPart), new UIPropertyMetadata(false, OnFundingVisibleValueChanged));


        /// <summary>
        /// Gets or sets the FundingVisible flag. If it is true, the funding combobox will be shown.
        /// </summary>
        /// <value>The value.</value>
        public bool FundingVisible
        {
            get { return (bool) GetValue(FundingVisibleProperty); }
            set { SetValue(FundingVisibleProperty, value); }
        }

        #endregion

        #region Dependency Property  FundingLevel 

        /// <summary>
        /// Dependency property FundingLevel
        /// </summary>
        public static readonly DependencyProperty FundingLevelProperty =
            DependencyProperty.Register("FundingLevel", typeof (FundingLevel), typeof (TechnicalInformationPart), new UIPropertyMetadata(FundingLevel.Full));


        /// <summary>
        /// Gets or sets the FundingLevel
        /// </summary>
        /// <value>The value.</value>
        public FundingLevel FundingLevel
        {
            get { return (FundingLevel) GetValue(FundingLevelProperty); }
            set { SetValue(FundingLevelProperty, value); }
        }

        #endregion

        /// <summary>
        /// Change something, when the value of the dependency property FundingVisible
        /// </summary>
        /// <param name="d">instance of TechnicalInformation</param>
        /// <param name="e">the new and old values</param>
        private static void OnFundingVisibleValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            bool fundingLevelVisible = (bool) e.NewValue;
            TechnicalInformationPart informationPart = (TechnicalInformationPart) d;
            informationPart.SetFundingVisibleChange(fundingLevelVisible);
        }

        /// <summary>
        /// This function rearranges the layout of this part in dependence of 
        /// a visible funding level selector or not.
        /// </summary>
        /// <param name="visible">if set to <c>true</c> [visible].</param>
        private void SetFundingVisibleChange(bool visible)
        {
            if (visible)
            {
                FundingLevelGrid.Visibility = Visibility.Visible ;
                Grid.SetRowSpan(InformationPanel, 1);
            }
            else
            {
                FundingLevelGrid.Visibility = Visibility.Collapsed;
                Grid.SetRowSpan(InformationPanel, 2);
            }
        }
    }
}